<?php
// $Id$

/**
 * Controller_File 控制器
 */
class Controller_File extends Controller_Prepare
{
    /**
     * 下载公共文档专版
     * 未来功能:在线编辑文档 @ 王风华 老师要求
     */
    public function actionIndex()
    {
        // Error handling 初步过滤获得的值，必须满足某种类型
        $Gfq       = isset($_GET['fq'])                                        ? $_GET['fq']       : NULL;
        $Gctgry_id = isset($_GET['ctgry_id']) && is_numeric($_GET['ctgry_id']) ? $_GET['ctgry_id'] : 3;
        $Gpage     = isset($_GET['page'])     && is_numeric($_GET['page'])     ? $_GET['page']     : 0;

        /**
         * 显示分页文件面板
         *
         * {return} $_SESSION
         */
        if(!isset($_SESSION['file_cur_page'])) {$_SESSION['file_cur_page'] = 1;}

        if(!isset($_SESSION['file_cur_ctgry'])) $_SESSION['file_cur_ctgry'] = 3;

        if($Gctgry_id && in_array($Gctgry_id, FileCategory::getSelfArrayId(3)))
        {
            $_SESSION['file_cur_ctgry'] = $Gctgry_id;
        }

        if($Gpage)
        {
            $_SESSION['file_cur_page'] = $Gpage;
        }

        /**
         * 右侧栏 (根据是否存在查询条件)
         *
         * @var array $files
         */
        if(CIB::_SQL_filter($Gfq))
        {
            $files = File::find('filename like ?', '%'.$Gfq.'%')->all()->order('file_id DESC')
				->limitPage(1, 50)->fetchPagination($filepg)->get();
        }
        else
        {
            $files = File::find(FileCategory::genCondition($_SESSION['file_cur_ctgry']))
                ->all()->order('file_id DESC')
                ->limitPage($_SESSION['file_cur_page'], Q::ini('appini/file_per_page'))->fetchPagination($filepg)->get();
        }

        /**
         * CSS HIGHLIGHT
         *
         * @var string $css
         */
        $css = ".filetree ul a[href$='{$Gctgry_id}.html']".HIGHLIGHT_CSS;

        $this->_view['filepg'] = $filepg;
        $this->_view['files']  = $files;
        $this->_view['css']    = $css;
    }
}